//
//  HomeItemView.m
//  Choice
//
//  Created by A-01 on 2020/6/15.
//  Copyright © 2020 Mac. All rights reserved.
//

#import "HomeItemView.h"

@implementation HomeItemView

- (instancetype)initWithFrame:(CGRect)frame{
    
    if ([super initWithFrame:frame]) {
        
        [self setupUI];
    }
    
    return self;
}


- (void)setupUI{
    
    self.userInteractionEnabled = YES;
    self.layer.cornerRadius = 10;
    self.layer.masksToBounds = YES;
    
    
    UILabel * titleLabel = [UILabel new];
    
    titleLabel.textColor = ZRBlackColor;
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    
    self.titleLabel = titleLabel;
    
    [self addSubview:self.titleLabel];
    
    
    UIImageView * iconImageView = [UIImageView new];
    
    self.iconImageView = iconImageView;
    
    [self addSubview:self.iconImageView];
}


-(void)layoutSubviews{
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.top.mas_equalTo(self).offset(16);
    }];
    
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.mas_equalTo(self.titleLabel);
        make.bottom.mas_equalTo(self).offset(-16);
        make.width.height.mas_equalTo(72);
    }];
}

- (void)setDict:(NSDictionary *)dict{
    
    _dict = dict;
    
    self.titleLabel.text = dict[@"title"];
    self.iconImageView.image = [UIImage imageNamed:dict[@"image"]];
    self.backgroundColor = [UIColor colorWithHexString:dict[@"color"]];
}

@end
